package com.lv.dhart.ui.activity;

import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.lv.dhart.R;
import com.lv.dhart.custom.fragment.baseframework.BaseActivity;
import com.lv.dhart.custom.fragment.baseframework.interfaces.LayoutName;
import com.lv.dhart.custom.fragment.baseframework.util.JumpParameter;
import com.lv.dhart.immersionbar.ImmersionBar;
import com.lv.dhart.ui.fragment.ASFragment;
import com.lv.dhart.ui.fragment.IssueFragment;
import com.lv.dhart.ui.fragment.CostFragment;
import com.lv.dhart.ui.fragment.fghome.HomeFragment;
import com.lzy.widget.AlphaIndicator;

import java.util.ArrayList;
import java.util.List;

@LayoutName("activity_bottom_bar")
public class BottomBarActivity extends BaseActivity {
    protected ImmersionBar mImmersionBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        changeStatusBarColor(R.color.red);
    }

    @Override
    public void initViews() {
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
        viewPager.setAdapter(new MainAdapter(getSupportFragmentManager()));
        AlphaIndicator alphaIndicator = (AlphaIndicator) findViewById(R.id.alphaIndicator);
        alphaIndicator.setViewPager(viewPager);
    }

    @Override
    public void initDatas(JumpParameter parameter) {
        mImmersionBar = ImmersionBar.with(this);
        mImmersionBar.execute();   //所有子类都将继承这些相同的属性
        checkVersion(false);
    }

    @Override
    public void setEvents() {

    }

    private static class MainAdapter extends FragmentStatePagerAdapter {
        @NonNull
        @Override
        public Object instantiateItem(@NonNull ViewGroup container, int position) {
            return super.instantiateItem(container, position);
        }

        @Override
        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
//            super.destroyItem(container, position, object);
        }

        private List<Fragment> fragments = new ArrayList<>();

        public MainAdapter(FragmentManager fm) {
            super(fm);
            fragments.add(new HomeFragment());
            fragments.add(new IssueFragment());
            fragments.add(new ASFragment());
            fragments.add(new CostFragment());
            fragments.add(new ASFragment());
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }


    }
}